package com.csoa.community.adapter;

import java.util.List;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.csoa.community.R;
import com.csoa.community.activity.EmailActivity;
import com.csoa.community.bean.EmailBean;
import com.csoa.community.utils.AndroidUtils;

public class EmailAdapter extends BaseAdapter {

	private EmailActivity activity;
	private List<EmailBean> emailBeans;

	public EmailAdapter(EmailActivity activity,
			List<EmailBean> officialDocs) {
		this.activity = activity;
		this.emailBeans = officialDocs;
	}

	@Override
	public int getCount() {
		return emailBeans == null ? 0 : emailBeans.size();
	}

	@Override
	public EmailBean getItem(int arg0) {
		return emailBeans == null ? null : emailBeans.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
		ViewHolder holder = null;
		if (null == convertView) {
			holder = new ViewHolder();
			view = AndroidUtils.inflateView(activity,
					R.layout.adapter_email_item, null);
			holder.content = (TextView) view
					.findViewById(R.id.adapterOfficialDocTV);
//			holder.issued = (Button) view
//					.findViewById(R.id.adapterOfficialIssuedBtn);
//			holder.update = (Button) view
//					.findViewById(R.id.adapterOfficialUpdateBtn);
			holder.time = (TextView) view
					.findViewById(R.id.adapterOfficialTimeTV);
			view.setTag(holder);
		} else {
			view = convertView;
			holder = (ViewHolder) view.getTag();
		}

		final EmailBean email = getItem(position);
		if (email != null) {
			holder.content.setText(email.Subject);
			holder.time.setText(email.Date);
//			boolean isRead = offDoc.isRead;
//			if(!isRead) {
//				holder.issued.setVisibility(View.VISIBLE);
//				holder.update.setVisibility(View.INVISIBLE);
//			}else {
//				holder.issued.setVisibility(View.INVISIBLE);
//				holder.update.setVisibility(View.VISIBLE);
//			}
//			holder.issued.setOnClickListener(new View.OnClickListener() {
//
//				@Override
//				public void onClick(View v) {
////					Intent intent = new Intent(activity,
////							OffDocDetailActivity.class);
////					intent.putExtra("ID", offDoc.ID);
////					intent.putExtra("RID", offDoc.RID);
////					intent.putExtra(GlobalVars.READ_TYPE, GlobalVars.READ_TYPE_TO_BE_READ);
////					intent.putExtra("issued", true);
////					activity.startActivity(intent);
//					activity.buildRequestMeeting(offDoc.ID, offDoc.RID,GlobalVars.ISSUED,true,GlobalVars.READ_TYPE_TO_BE_READ,GlobalVars.TO_BE_READ);
//				}
//			});
//			holder.update.setOnClickListener(new View.OnClickListener() {
//
//				@Override
//				public void onClick(View v) {
////					Intent intent = new Intent(activity,
////							OffDocDetailActivity.class);
////					intent.putExtra("ID", offDoc.ID);
////					intent.putExtra("RID", offDoc.RID);
////					intent.putExtra(GlobalVars.READ_TYPE, GlobalVars.READ_TYPE_HAVE_READ);
////					intent.putExtra("isupdate", true);
////					activity.startActivity(intent);
//					
//					activity.buildRequestMeeting(offDoc.ID, offDoc.RID,GlobalVars.ISUPDATE,true,GlobalVars.READ_TYPE_HAVE_READ,GlobalVars.HAVE_READ);
//				}
//			});

		}
		return view;
	}

	public final class ViewHolder {

		public TextView content;
//		public Button issued;
//		public Button update;
		public TextView time;

	}

}
